<?php
$maint_log_subhead = $maint_log_title = "Edit a Project";
require_once("include_functions.php");
require_once("include_header.php");
?>
<div id="content">
<?php
	// clean variable for sql query
	$projId = clean($_GET['projId']);
	
	// query for all params on proj to edit
	$sql =	"SELECT * ".
			"FROM projects ".
			"WHERE projId = '". $projId ."';";
	if ($result = mysql_query($sql)) echo mysql_error();
	$proj = mysql_fetch_array($result, MYSQL_ASSOC);
?>

	<div class="form-box">
		<form action="manage_projects.php" method="post">
			<div>
				<label for="projName">Project Name:</label>
				<input type="text" name="projName" value="<?php echo $proj['projName'];?>" id="projName" />
			</div>
			<div>
				<label for="workerAssignedId">Assigned To:</label>
				<select name="workerAssignedId" id="workerAssignedId">
		<?php
			// Gather full list of workers for select box
			$sql =	"SELECT workerId, workerName ". 
					"FROM workers";
			if(!$result = mysql_query($sql)) echo mysql_error();
			while($worker = mysql_fetch_array($result)) {
				if($worker['workerId'] == $proj['workerAssignedId']) {
					echo "\t\t\t<option value=\"$worker[workerId]\" selected=\"selected\">$worker[workerName]</option>\n";
				} else {
					echo "\t\t\t\t\t<option value=\"$worker[workerId]\">$worker[workerName]</option>\n";
				}
			}
		?>
				</select>
			</div>
			<div>
				<label for="projCreator">Created By:</label>
				<input type="text" name="projCreator" value="<?php echo $proj['projCreator'];?>" id="projCreator" />
			</div>
			<div>
				<label for="projCreatorEmail">Creator Email:</label>
				<input type="text" name="projCreatorEmail" value="<?php echo $proj['projCreatorEmail'];?>" id="projCreatorEmail" />
			</div>
<!-- Start Date Picker script -->
			<div>
				<label for="projRequestedDate">Requested Complete By:</label>
				<input name='projRequestedDate' type='text' value='<?php echo $proj['projRequestedDate'];?>' id='projRequestedDate' />
				<script type="text/javascript">
					window.addEvent('load', function() {
						new DatePicker('#projRequestedDate', {
							inputOutputFormat: 'Y-m-d',
							format: 'm-d-Y',
							yearPicker: false
						});
					});
				</script>
			</div>
<!-- End Date Picker script -->
			<div>
				<label for="projPriority">Priority:</label>
				<select name="projPriority" id="projPriority" />
<?php
	for($i=1; $i<=5; $i++) {
		if($i == $proj['projPriority']){
			echo "\t\t\t\t\t<option value=\"".$i."\" selected=\"selected\">".$i."</option>\n";
		} else {
			echo "\t\t\t\t\t<option value=\"".$i."\">".$i."</option>\n";
		}
	}
?>
				</select>
			</div>
			<div>
				<label for="projDescription">Description:</label>
				<textarea rows="10" cols="50" name="projDescription" id="projDescription"><?php echo $proj['projDescription'];?></textarea>
			</div>
			<div class="buttons">
				<input type="hidden" name="action" value="edit">
				<input type="hidden" name="projId" value="<?php echo $proj['projId'];?>">
				<input type="submit" name="submit" value="submit">
				<input type="reset" value="reset"></td></tr>
			</div>
		</form>
	</div>
</div>
<?php
require_once("include_footer.php");
?>
